clear

*Load Data
use "./data_geo.dta", clear

*****************************************************************************
*** Setup state-level data ***

drop if rssd9200 == "0"
keep if  rssd9210>0 & rssd9210< 57

*keep if year_q < tq(1995q1)

gen loans = rcfd1400
replace loans = rcfd1400+rcfd2165 if year_q < tq(1984q1)

gen c_p_i = cpi/100
gen r_loans = loans/c_p_i 
gen r_ci = rcfd1600/c_p_i
gen r_rlest = rcfd1410/c_p_i
gen r_con = rcfd1975/c_p_i
gen r_ag = rcfd1590/c_p_i

gen Quarter = quarter(date2)
gen Year = year(date2) 

gen bhc = 0
replace bhc = 1 if rssd9379 != 0

sort year_q
by year_q: egen p95 = pctile(rcfd2170), p(95)
by year_q: egen p99 = pctile(rcfd2170), p(99)

by year_q: egen natl_loans = sum(r_loans)
by year_q: egen sa_small_natl = sum(r_loans) if rcfd2170 < p95 & bhc==0
by year_q: egen sa_big_natl = sum(r_loans) if rcfd2170 >= p95 & bhc == 0
by year_q: egen bhc_small_natl = sum(r_loans) if rcfd2170 < p95 & bhc==1
by year_q: egen bhc_big_natl = sum(r_loans) if rcfd2170 >= p95 & bhc==1

sort rssd9210 year_q

by rssd9210 year_q: egen s50 = pctile(rcfd2170), p(50)
by rssd9210 year_q: egen s80 = pctile(rcfd2170), p(80)
by rssd9210 year_q: egen s95 = pctile(rcfd2170), p(95)
by rssd9210 year_q: egen s99 = pctile(rcfd2170), p(95)

by rssd9210 year_q: egen sa_small_loans = sum(r_loans) if rcfd2170 < p95 & bhc==0
by rssd9210 year_q: egen sa_big_loans = sum(r_loans) if rcfd2170 >= p95 & bhc == 0
by rssd9210 year_q: egen bhc_small_loans = sum(r_loans) if rcfd2170 < p95 & bhc==1
by rssd9210 year_q: egen bhc_big_loans = sum(r_loans) if rcfd2170 >= p95 & bhc==1
by rssd9210 year_q: egen small_assets = sum(rcfd2170) if rcfd2170 < p95
by rssd9210 year_q: egen small_aff_assets = sum(rcfd2170) if rcfd2170 < p95 & bhc==1
by rssd9210 year_q: egen all_assets = sum(rcfd2170)
by rssd9210 year_q: gen small_share = small_assets/all_assets
by rssd9210 year_q: gen small_share2 = small_aff_assets/all_assets
*replace small_share2 = 0 if small_share2 == .

by rssd9210 year_q: egen agg_loans = sum(r_loans)

replace intra = 1 if intra == .
replace inter =1 if inter == .

collapse (mean) small_share small_share2 agg_loans sa_small_loans sa_big_loans bhc_small_loans bhc_big_loans natl_loans sa_small_natl sa_big_natl bhc_small_natl bhc_big_natl c_p_i pi_pchg gdp_chg pce_chg vwretx hpi_chg rr inter intra Quarter Year, by (rssd9210 year_q)


xtset rssd9210 year_q

*******************************************************************************
*** Panel A ***

gen rr_dereg = rr*intra
gen rr_dereg1 = L1.rr*intra
gen rr_dereg2 = L2.rr*intra
gen rr_dereg3 = L3.rr*intra
gen rr_dereg4 = L4.rr*intra

gen rr_inter = rr*inter
gen rr_inter1 = L1.rr*inter
gen rr_inter2 = L2.rr*inter
gen rr_inter3 = L3.rr*inter
gen rr_inter4 = L4.rr*inter

gen loans3 = ln(agg_loans)-ln(L.agg_loans)
gen sas_loans3 = ln(sa_small_loans) - ln(L.sa_small_loans)
gen sab_loans3 = ln(sa_big_loans) - ln(L.sa_big_loans)
gen bhcs_loans3 = ln(bhc_small_loans) - ln(L.bhc_small_loans)
gen bhcb_loans3 = ln(bhc_big_loans) - ln(L.bhc_big_loans)

*All Banks
xtreg loans3 L(1/4).loans3 L(0/4).pi_pchg L(0/4).hpi_chg intra inter rr_dereg rr_dereg1 rr_dereg2 rr_dereg3 rr_dereg4 rr_inter rr_inter1 rr_inter2 rr_inter3 rr_inter4 i.year_q, fe vce(cluster year_q) nonest
lincom rr_dereg + rr_dereg1 + rr_dereg2 + rr_dereg3 + rr_dereg4
lincom rr_inter + rr_inter1 + rr_inter2 + rr_inter3 + rr_inter4

*Small Affiliated Banks
xtreg bhcs_loans3 L(1/4).bhcs_loans3 L(0/4).pi_pchg L(0/4).hpi_chg intra inter rr_dereg rr_dereg1 rr_dereg2 rr_dereg3 rr_dereg4 rr_inter rr_inter1 rr_inter2 rr_inter3 rr_inter4 i.year_q, fe vce(cluster year_q) nonest
lincom rr_dereg + rr_dereg1 + rr_dereg2 + rr_dereg3 + rr_dereg4
lincom rr_inter + rr_inter1 + rr_inter2 + rr_inter3 + rr_inter4

*Small Stand Alone Banks
xtreg sas_loans3 L(1/4).sas_loans3 L(0/4).pi_pchg L(0/4).hpi_chg intra inter rr_dereg rr_dereg1 rr_dereg2 rr_dereg3 rr_dereg4 rr_inter rr_inter1 rr_inter2 rr_inter3 rr_inter4 i.year_q, fe vce(cluster year_q) nonest
lincom rr_dereg + rr_dereg1 + rr_dereg2 + rr_dereg3 + rr_dereg4
lincom rr_inter + rr_inter1 + rr_inter2 + rr_inter3 + rr_inter4

*Large Affiliated Banks
xtreg bhcb_loans3 L(1/4).bhcb_loans3 L(0/4).pi_pchg L(0/4).hpi_chg intra inter rr_dereg rr_dereg1 rr_dereg2 rr_dereg3 rr_dereg4 rr_inter rr_inter1 rr_inter2 rr_inter3 rr_inter4 i.year_q, fe vce(cluster year_q) nonest
lincom rr_dereg + rr_dereg1 + rr_dereg2 + rr_dereg3 + rr_dereg4
lincom rr_inter + rr_inter1 + rr_inter2 + rr_inter3 + rr_inter4

*Large Stand Alone Banks
xtreg sab_loans3 L(1/4).sab_loans3 L(0/4).pi_pchg L(0/4).hpi_chg intra inter rr_dereg rr_dereg1 rr_dereg2 rr_dereg3 rr_dereg4 rr_inter rr_inter1 rr_inter2 rr_inter3 rr_inter4 i.year_q, fe vce(cluster year_q) nonest
lincom rr_dereg + rr_dereg1 + rr_dereg2 + rr_dereg3 + rr_dereg4
lincom rr_inter + rr_inter1 + rr_inter2 + rr_inter3 + rr_inter4

*******************************************************************************
*** Panel B ***

egen share50 = pctile(small_share2), p(50)
egen share50b = pctile(small_share), p(50)

xtreg pi_pchg hpi_chg inter rr_inter rr_inter1 rr_inter2 rr_inter3 rr_inter4 i.year_q if small_share < share50b, fe vce(cluster rssd9210) 
lincom rr_inter + rr_inter1 + rr_inter2 + rr_inter3 + rr_inter4

xtreg pi_pchg hpi_chg inter rr_inter rr_inter1 rr_inter2 rr_inter3 rr_inter4 i.year_q if small_share >= share50b, fe vce(cluster rssd9210) nonest
lincom rr_inter + rr_inter1 + rr_inter2 + rr_inter3 + rr_inter4

xtreg pi_pchg hpi_chg inter rr_inter rr_inter1 rr_inter2 rr_inter3 rr_inter4 i.year_q if small_share2 < share50, fe vce(cluster rssd9210) 
lincom rr_inter + rr_inter1 + rr_inter2 + rr_inter3 + rr_inter4

xtreg pi_pchg hpi_chg inter rr_inter rr_inter1 rr_inter2 rr_inter3 rr_inter4 i.year_q if small_share2 >= share50, fe vce(cluster rssd9210) nonest
lincom rr_inter + rr_inter1 + rr_inter2 + rr_inter3 + rr_inter4

*******************************************************************************
